package org.callisto;

public enum EventType {
	NOTE_ON (javax.sound.midi.ShortMessage.NOTE_ON),
	NOTE_OFF (javax.sound.midi.ShortMessage.NOTE_OFF),
	TIMING_CLOCK (javax.sound.midi.ShortMessage.TIMING_CLOCK), 
	UNKNOWN(-1);
	
	private int type; 
	
	EventType(int type) {
		this.type=type;
	}
	
	public static boolean isValid(int type) throws Exception {
		switch (type) {
			case javax.sound.midi.ShortMessage.NOTE_ON: ;
			case javax.sound.midi.ShortMessage.NOTE_OFF: ;
			case javax.sound.midi.ShortMessage.TIMING_CLOCK:  return true;
			default: return false;
		}
	}
	
	public static EventType get(int type) throws Exception {
		switch (type) {
			case javax.sound.midi.ShortMessage.NOTE_ON: return EventType.NOTE_ON;
			case javax.sound.midi.ShortMessage.NOTE_OFF: return EventType.NOTE_OFF;
			case javax.sound.midi.ShortMessage.TIMING_CLOCK: return EventType.TIMING_CLOCK;
			default: return EventType.UNKNOWN;
		}
	}
	
	public String toString() {
		return this.name();
	}
	
	public int getMidiStatusCode() {
		return type;
	}

	public int type() {
		return type;
	}
}
